package com.wxm.remotemeter.web.action;

import org.apache.commons.lang.StringUtils;

import com.talkweb.ncfw.data.IDataMap;
import com.talkweb.ncfw.data.Page;
import com.talkweb.ncfw.data.ProcessResult;
import com.talkweb.ncfw.exceptions.BaseException;
import com.talkweb.ncfw.web.struts2.ExtGridBaseAction;
import com.talkweb.ncfw.web.utils.HttpServletUtils;
import com.wxm.remotemeter.persistence.entity.Meter;
import com.wxm.remotemeter.persistence.entity.MeterType;
import com.wxm.remotemeter.service.IMeterService;
import com.wxm.remotemeter.service.IMeterTypeService;

/**
 * <p>文件名称: MeterAction.java</p>
 * <p>文件描述: 表具控制类</p>
 * <p>版权所有: 版权所有(C)2010</p>
 * <p>内容摘要: 简要描述本文件的内容，包括主要模块、函数及能的说明</p>
 * <p>其他说明: 其它内容的说明</p>
 * <p>完成日期: 2012-2-19</p>
 * <p>修改记录1:</p>
 * <pre>
 *    修改日期:
 *    修 改 人:
 *    修改内容:
 * </pre>
 * <p>修改记录2：…</p>
 * @author  Wuqingming
 */
public class MeterAction extends ExtGridBaseAction {
	/**
	 * 
	 */
	private static final long serialVersionUID = 9215032482950649806L;
	
	private IMeterTypeService meterTypeService;
	private IMeterService meterService;
	private MeterType meterType;
	private Meter meter;
	
	public IMeterTypeService getMeterTypeService() {
		return meterTypeService;
	}
	public void setMeterTypeService(IMeterTypeService meterTypeService) {
		this.meterTypeService = meterTypeService;
	}
	public IMeterService getMeterService() {
		return meterService;
	}
	public void setMeterService(IMeterService meterService) {
		this.meterService = meterService;
	}
	
	public MeterType getMeterType() {
		return meterType;
	}
	public void setMeterType(MeterType meterType) {
		this.meterType = meterType;
	}
	public Meter getMeter() {
		return meter;
	}
	public void setMeter(Meter meter) {
		this.meter = meter;
	}
	
	/**
	 * 
	 * @author：Wuqingming 	        
	 * @date：2012-2-19
	 * @Description：录入表具类型信息
	 * @return
	 * @throws BaseException
	 */
	public String inputMeterType () throws BaseException {
		ProcessResult result = null;
		if (StringUtils.isEmpty(meterType.getTypeid())) {	//添加
			this.meterTypeService.add(meterType);
			result = new ProcessResult(true, "表具类型信息添加成功");
		} else {	//修改
			this.meterTypeService.update(meterType);
			result = new ProcessResult(true, "表具类型信息修改成功");
		}
		if (HttpServletUtils.isAjaxRequest(this.getRequest())) {
			HttpServletUtils.outJson(this.getResponse(), result);
		}
		return null;
	}

	/**
	 * 
	 * @author：Wuqingming 	        
	 * @date：2012-2-19
	 * @Description：删除表具类型信息
	 * @return
	 * @throws BaseException
	 */
	public String deleteMeterType () throws BaseException {
		String typeids = this.getParameter("typeids");
		String[] typeidArray = null;
		if (!StringUtils.isEmpty(typeids)) {
			typeidArray = typeids.split(",");
		}
		this.meterTypeService.deleteBatch(typeidArray);
		ProcessResult result = new ProcessResult(true, "表具类型信息删除成功");
		if (HttpServletUtils.isAjaxRequest(this.getRequest())) {
			HttpServletUtils.outJson(this.getResponse(), result);
		}
		return null;
	}
	
	/**
	 * 
	 * @author：Wuqingming 	        
	 * @date：2012-2-19
	 * @Description：列出表具类型信息
	 * @return
	 * @throws BaseException
	 */
	public String listMeterType () throws BaseException {
		Page<MeterType> page = this.getPage();
		IDataMap<String, Object> condition = this.getParameterMap();
		page = this.meterTypeService.find(page, condition);
		if (HttpServletUtils.isAjaxRequest(this.getRequest())) {
			this.bindDataGrid(page);
		}
		return null;
	}
	
	/**
	 * 
	 * @author：Wuqingming 	        
	 * @date：2012-2-19
	 * @Description：录入表具信息
	 * @return
	 * @throws BaseException
	 */
	public String inputMeter () throws BaseException {
		ProcessResult result = null;
		if (StringUtils.isEmpty(meter.getMeterid())) {	//添加
			this.meterService.add(meter);
			result = new ProcessResult(true, "表具信息添加成功");
		} else {	//修改
			this.meterService.update(meter);
			result = new ProcessResult(true, "表具信息修改成功");
		}
		if (HttpServletUtils.isAjaxRequest(this.getRequest())) {
			HttpServletUtils.outJson(this.getResponse(), result);
		}
		return null;
	}

	/**
	 * 
	 * @author：Wuqingming 	        
	 * @date：2012-2-19
	 * @Description：删除表具信息
	 * @return
	 * @throws BaseException
	 */
	public String deleteMeter () throws BaseException {
		String meterids = this.getParameter("meterids");
		String[] meteridArray = null;
		if (!StringUtils.isEmpty(meterids)) {
			meteridArray = meterids.split(",");
		}
		this.meterService.deleteBatch(meteridArray);
		ProcessResult result = new ProcessResult(true, "表具信息删除成功");
		if (HttpServletUtils.isAjaxRequest(this.getRequest())) {
			HttpServletUtils.outJson(this.getResponse(), result);
		}
		return null;
	}
	
	/**
	 * 
	 * @author：Wuqingming 	        
	 * @date：2012-2-19
	 * @Description：列出表具类型信息
	 * @return
	 * @throws BaseException
	 */
	public String listMeter () throws BaseException {
		Page<Meter> page = this.getPage();
		IDataMap<String, Object> condition = this.getParameterMap();
		page = this.meterService.find(page, condition);
		if (HttpServletUtils.isAjaxRequest(this.getRequest())) {
			this.bindDataGrid(page);
		}
		return null;
	}

}

